package cn.gdcp.demob;


import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * Created by yls on 2018/12/3.
 */

public class StuContentProvider extends ContentProvider {
    private StuOpenHelper openHelper;
    private static final String AUTOHORITY = "com.gdcp.student";
    private static UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    static {
        uriMatcher.addURI(AUTOHORITY, "student", 1);
        uriMatcher.addURI(AUTOHORITY, "score", 2);
    }
    @Override
    public boolean onCreate() {
        openHelper = new StuOpenHelper(getContext(),"stu.db",null, 1);
        return true;
    }
    @Override
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
        SQLiteDatabase sqLiteDatabase = openHelper.getWritableDatabase();
        sqLiteDatabase.insert("student", null, contentValues);
        return uri;
    }
    @Override
    public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {
        SQLiteDatabase sqLiteDatabase = openHelper.getWritableDatabase();
        int Rows=sqLiteDatabase.delete("student",s,strings);
        return Rows;
    }
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String orderBy) {
        SQLiteDatabase sqLiteDatabase = openHelper.getWritableDatabase();
        Cursor cursor1 = sqLiteDatabase.query("student", null, selection,selectionArgs,null, null, orderBy);
        return cursor1;
    }
    @Override
    public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String s, @Nullable String[] strings) {
        SQLiteDatabase sqLiteDatabase= openHelper.getWritableDatabase();
        int Rows=sqLiteDatabase.update("student",contentValues,s,strings);
        return Rows;
    }
    @Override
    public String getType(@NonNull Uri uri) {
        return null;
    }

}
